home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 151-175 / scopedisk155 / zkick / mmu.asm < prev    next >
Assembly Source File  |  1995-03-19  |  5KB  |  183 lines

  1. ;======================================================================
  2. ;
  3. ;    Borrowed From:
  4. ;    
  5. ;    SetCPU V1.60
  6. ;    by Dave Haynie, April 13, 1990
  7. ;
  8. ;======================================================================
  9.  
  10.  
  11.     SECTION code
  12.  
  13.  
  14.     NOLIST
  15.     include "include:exec/types.i"
  16.     include "include:exec/execbase.i"
  17.     include "include:exec/tasks.i"
  18.     LIST
  19.  
  20.     XREF _LVOSupervisor
  21.     XREF _LVOFindTask
  22.  
  23.     XDEF _GetCPUType
  24.      XDEF _GetMMUType
  25.  
  26.     INCLUDE "zkick.i"
  27.     INCLUDE "mmu.i"
  28.  
  29.  
  30. ;======================================================================
  31. ;
  32. ;    This routine checks CPU flags early in ExecBase for extended
  33. ;    CPUs that test as a 68020 under 1.3.  If these flags are set,
  34. ;    the actual CPU/MMU type test can be skipped.
  35. ;
  36. ;======================================================================
  37.  
  38. TestFlags:
  39.     moveq.l    #0,d0
  40.     btst.b    #AFB_68040,ATNFLGS(a6)    ; Does the OS think an '040 is here?
  41.     beq    NoEarly40
  42.     move.l    #68040,d0
  43.     rts
  44. NoEarly40:
  45.     btst.b    #AFB_68030,ATNFLGS(a6)    ; Does the OS think an '030 is here?
  46.     beq    NoEarly30
  47.     move.l    #68030,d0        ; Sure does...
  48. NoEarly30:
  49.     rts
  50.  
  51.  
  52. ;======================================================================
  53. ;
  54. ;    This function returns the type of the CPU in the system as a
  55. ;    longword: 68000, 68010, 68020, or 68030.  The testing must be done
  56. ;    in reverse order, in that any higher CPU also has the bits set for
  57. ;    a lower CPU.  Also, since 1.3 doesn't recognize the 68030, if I
  58. ;    find the 68020 bit set, I always check for the presence of a 
  59. ;    68030.
  60. ;
  61. ;    This routine should be the first test routine called under 1.2
  62. ;    and 1.3.
  63. ;
  64. ;    ULONG GetCPUType();
  65. ;
  66. ;======================================================================
  67.  
  68. _GetCPUType:
  69.     move.l    4,a6            ; Get ExecBase
  70.     jsr    TestFlags        ; Check extended CPU types
  71.     cmp.l    #0,d0
  72.     beq    CPURealTest
  73.     rts
  74. CPURealTest:
  75.     movem.l    a4/a5,-(sp)        ; Save this register
  76.     btst.b    #AFB_68020,ATNFLGS(a6)    ; Maybe a 68020
  77.     bne    FindReal32
  78.     btst.b    #AFB_68010,ATNFLGS(a6)    ; Maybe a 68010?
  79.     bne    Found10
  80.     move.l    #68000,d0        ; Just a measley '000
  81.     movem.l    (sp)+,a4/a5
  82.     rts
  83. Found10:
  84.     move.l    #68010,d0        ; Yup, we're an '010
  85.     movem.l    (sp)+,a4/a5
  86.     rts
  87. FindReal32:
  88.     move.w    LIB_VERSION(a6),d0    ; Are we in 2.0?
  89.     cmp.w    #36,d0            ; If so, we don't need to test
  90.     bge    No40
  91.  
  92.     lea.l    SuperGCT,a5        ; Get the start of the supervisor code
  93.     jsr    _LVOSupervisor(a6)
  94.  
  95.     btst    #CIB_BURST,d0        ; Do we have a set burst bit?
  96.     beq    No30
  97.     move.l    #68030,d0        ; It's a 68030
  98.     bset.b    #AFB_68030,ATNFLGS(a6)
  99.     movem.l    (sp)+,a4/a5
  100.     rts
  101. No30:    
  102.     btst    #CIB_ENABLE40,d1    ; Do we have 040 cache enable?
  103.     beq    No40
  104.     move.l    #68040,d0        ; It's a 68040
  105.     bset.b    #AFB_68040,ATNFLGS(a6)
  106.     movem.l    (sp)+,a4/a5
  107.     rts
  108. No40:
  109.     move.l    #68020,d0        ; Guess we're a plain old '020
  110.     movem.l    (sp)+,a4/a5
  111.     rts
  112.  
  113.     ; This routine tries to set a few interesting CACR bits, and
  114.     ; returns the actual register value that took in d0.
  115. SuperGCT:
  116.     _MOVEC    cacr,d1            ; Get the cache register
  117.     move.l    d1,d0            ; Make a copy
  118.     bset    #CIB_BURST,d0        ; Set the inst burst bit 030
  119.     bclr    #CIB_ENABLE,d0        ; Clear the inst cache bit 030
  120.     bset    #CIB_ENABLE40,d0    ; Set the inst cache bit 040
  121.     _MOVEC    d0,cacr            ; Try to set the CACR
  122.     _MOVEC    cacr,d0            ; Save the real value
  123.     _MOVEC    d1,cacr            ; Restore it
  124.     rte
  125.  
  126. ;======================================================================
  127. ;
  128. ;    This function returns 0L if the system contains no MMU, 
  129. ;    68851L if the system does contain an 68851, or the CPU number
  130. ;    for CPUs with integral CPUs.
  131. ;
  132. ;    This routine seems to lock up on at least some CSA 68020 
  133. ;    boards, though it runs just fine on those from Ronin and 
  134. ;    Commodore, as well as all 68030 boards it's been tested on.
  135. ;
  136. ;    ULONG GetMMUType()
  137. ;
  138. ;======================================================================
  139.  
  140. _GetMMUType:
  141.     move.l    4,a6            ; Get ExecBase
  142.     jsr    TestFlags        ; Check extended CPU types
  143.     cmp.l    #0,d0
  144.     beq    MMURealTest
  145.     rts
  146.  
  147.     ; For any other machine, a real test must be done.  The test will
  148.     ; try an MMU instruction.  The instruction will fail unless we're
  149.     ; on a "bogus MMU" system, where the FPU responds as an MMU.
  150. MMURealTest:
  151.     movem.l    a3/a4/a5,-(sp)        ; Save this stuff
  152.     move.l    #0,a1    
  153.     jsr    _LVOFindTask(a6)    ; Call FindTask(0L)
  154.     move.l    d0,a3
  155.  
  156.     move.l    TC_TRAPCODE(a3),a4    ; Change the exception vector
  157.     move.l    #MMUTraps,TC_TRAPCODE(a3)
  158.     
  159.     move.l    #-1,d0            ; Try to detect undecode FPU
  160.     subq.l    #4,sp            ; Get a local variable
  161.     _PMOVE    tc,(sp)            ; Let's try an MMU instruction
  162.     addq.l    #4,sp            ; Return that local
  163.     move.l    a4,TC_TRAPCODE(a3)    ; Reset exception stuff
  164.     movem.l    (sp)+,a3/a4/a5        ; and return the registers
  165.     rts
  166.  
  167.     ; This is the exception code.  No matter what machine we're on,
  168.     ; we get an exception.  If the MMU's in place, we should get a
  169.     ; privilige violation; if not, an F-Line emulation exception.
  170. MMUTraps:
  171.     move.l    (sp)+,d0        ; Get Amiga supplied exception #
  172.     cmpi    #11,d0            ; Is it an F-Line?
  173.     beq    MMUNope            ; If so, go to the fail routine
  174.     move.l    #68851,d0        ; We have MMU
  175.     addq.l    #4,2(sp)        ; Skip the MMU instruction
  176.     rte
  177. MMUNope:
  178.     moveq.l    #0,d0            ; It dinna woik,
  179.     addq.l    #4,2(sp)        ; Skip the MMU instruction
  180.     rte
  181.  
  182.     END
  183.